#include<stdio.h>
# include <stdlib.h>
#include<string.h>
#include "sdf.h"
#include<time.h>
#include <openssl/bn.h>
int SDF_OpenDevice( void ** phDeviceHandle)
{
 return SDF_OK;
}
int SDF_CloseDevice( void * hDeviceHandle)
{
 return SDF_OK;
}
int SDF_GetDeviceInfo(void * hSessionHandle,DEVICEINFO * pstDeviceInfo)
{
 DEVICEINFO di;
 strcpy(di.IssuerName,"tzjSDF");
 strcpy(di.DeviceName,"SDFtzj20181212");
 strcpy(di.DeviceSerial,"20210425");
 di.DeviceVersion=1;
 (*pstDeviceInfo)= di; 
 
 return SDF_OK;
}
int SDF_GenerateRandom (void * hSessionHandle,unsigned int uiLength,unsigned char * pucRandom)
{
 BIGNUM *bn;
        
        int i;
        bn = BN_new(); //生成一个BIGNUM结构
        //int bits = 20;
        int top = -1;
        int bottom = 1;
        BN_rand(bn, uiLength, top, bottom); //生成指定bits的随机数
        char *a = BN_bn2hex(bn); //转化成16进制字符串
        puts(a);
        printf("\n");
        for(i=0;*(a+i)!='\0';i++)
        {
            *(pucRandom+i)=*(a+i);
        }
        *(pucRandom+i)='\0';
        BN_free(bn); //释放BIGNUM结构
        return SDF_OK;
}
